package edu.uhcl.team_drone.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import edu.uhcl.team_drone.assets.Assets;
import edu.uhcl.team_drone.game.ProjectGame;

public class SplashScreen implements Screen {

    private Stage stage = new Stage();
    private Table table = new Table();
    private ProjectGame game;

    private Texture splashTexture ;
    private Image splashImage;

    private boolean animationDone = false;

    public SplashScreen(ProjectGame gameIn) {
        this.game = gameIn;
        splashTexture = Assets.manager.get("SplashScreenImage.png", Texture.class);
        splashImage = new Image(splashTexture);
    }

    @Override
    public void show() {
        splashImage.addAction(
                Actions.sequence(
                        Actions.alpha(0), Actions.fadeIn(0.5f),
                        Actions.delay(1.5f), Actions.fadeOut(0.5f),
                        Actions.run(new Runnable() {
                            @Override
                            public void run() {
                                animationDone = true;
                            }
                        })));

        table.setFillParent(true);
        table.add(splashImage);
        stage.addActor(table);
    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0, 0, 0, 1); //sets clear color to black
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); //clear the batch
        stage.act(); //update all actors
        stage.draw(); //draw all actors on the Stage.getBatch()

        if (animationDone) {
            game.setScreen(new MainMenuScreen(game));
        }
    }

    @Override
    public void resize(int width, int height) {
    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }

    @Override
    public void hide() {
    }

    @Override
    public void dispose() {
    }

}
